package com.zhj.springbootinit.manager;

import com.yupi.yucongming.dev.client.YuCongMingClient;
import com.yupi.yucongming.dev.common.BaseResponse;
import com.yupi.yucongming.dev.model.DevChatRequest;
import com.yupi.yucongming.dev.model.DevChatResponse;
import com.zhj.springbootinit.common.ErrorCode;
import com.zhj.springbootinit.exception.ThrowUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AIManager {
    @Resource
    private YuCongMingClient client;

    /**
     * AI对话
     * @param userInput
     * @return
     */
    public String getMessageByAI(String userInput) {
        // 设置请求参数
        DevChatRequest devChatRequest = new DevChatRequest(); // 请求体
        devChatRequest.setModelId(1766667440903114753L); // 机台id
        devChatRequest.setMessage(userInput); // 请求信息

        // 发送请求
        BaseResponse<DevChatResponse> response = client.doChat(devChatRequest);
        // 异常处理 or 返回
        ThrowUtils.throwIf(response == null, ErrorCode.OPERATION_ERROR, "AI响应错误，请修改请求参数后重试");

        return response.getData().getContent();
    }
}
